<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;

class ShopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $p = [
            1=>['id'=>1,'name'=>'风景1','price'=>9.9,'des'=>'好风光'],
            2=>['id'=>2,'name'=>'风景2','price'=>19.9,'des'=>'江山如画'],
            3=>['id'=>3,'name'=>'风景3','price'=>29.9,'des'=>'大好河山']
        ];        
        return view('sh',['p'=>$p]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function shopping($id)
    {
        $p = [
            1=>['id'=>1,'name'=>'风景1','price'=>9.9,'des'=>'好风光'],
            2=>['id'=>2,'name'=>'风景2','price'=>19.9,'des'=>'江山如画'],
            3=>['id'=>3,'name'=>'风景3','price'=>29.9,'des'=>'大好河山']
        ];
        $ps = $p[$id];
        Cart::add($ps['id'],$ps['name'],1,$ps['price']);

        return redirect()->route('create');
        
    }
    // 购物车信息
    public function create()
    {
        // 购物车所有信息
        $cart = Cart::content();
        // 总额 不含税
        $total = Cart::total();
        // 购物车商品数量
        $count = Cart::count();
        return view('shop_li',['cart'=>$cart,'total'=>$total,'count'=>$count]);          
    }
    // 清除购物车
    public function del()
    {
        Cart::destroy();
        return redirect()->route('create');

    }

    // 移除单个商品
    public function dell($rowId)
    {
        Cart::remove($rowId);
        return redirect()->route('create');
        // echo 11;
    }
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
              
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
